import { RouterProvider, createBrowserRouter } from "react-router-dom";
import { BASENAME } from "./api/common";
import { RequireAuth } from "./components/RequireAuth";
import { IPSetDetailsPage } from "./pages/IPSetDetailsPage";
import { IPSetLayout } from "./pages/IPSetLayout";
import { LoginPage } from "./pages/LoginPage";
import { NotFoundPage } from "./pages/NotFoundPage";

const router = createBrowserRouter(
  [
    {
      path: "/login",
      element: <LoginPage />,
    },
    {
      path: "/ipset",
      element: (
        <RequireAuth>
          <IPSetLayout />
        </RequireAuth>
      ),
      children: [
        {
          path: ":setname",
          element: <IPSetDetailsPage />,
        },
      ],
    },
    {
      path: "*",
      element: <NotFoundPage />,
    },
  ],
  { basename: BASENAME }
);

export default function App() {
  return <RouterProvider router={router} />;
}
